package com.w7vm.menuweb.dao;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.w7vm.menuweb.entity.ContratoPagamentoWeb;
import com.w7vm.menuweb.entity.ContratoRestaurantesWeb;
import com.w7vm.menuweb.utility.ConstantesEJB;


@Stateless
public class ContratoPagamentoDAO extends GenericDAO<ContratoPagamentoWeb> {
	
	ConstantesEJB constEJB = new ConstantesEJB();
	
	@PersistenceContext
	private EntityManager em;
	
	public ContratoPagamentoDAO() {
		super(ContratoPagamentoWeb.class);
		// TODO Auto-generated constructor stub
	}
	
	
//	public int deleteContratoPagamento(int idContrato){
//		System.out.println("[IAM-EJB][deleteContratoPagamento] :"+ idContrato);
//		try{
//			Map<String, Object> parameters = new HashMap<String, Object>();
//			parameters.put("id", idContrato);   
//			super.delete(ContratoPagamentoWeb.DELETE_PAGAMENTOCONTRATO_BY_ID, parameters);
//			return 1;
//		}
//		catch (Exception e) {
//			return -1;
//		}
//	}
	
	public int updateParcelaPagamento(ContratoPagamentoWeb contratoPagamentoEntity){

		System.out.println("[CONTRATO - DAO][updateParcelaPagamento] :");
		int updated = -1;
		ContratoPagamentoWeb contratoPagEntity = new ContratoPagamentoWeb();

		try{
			contratoPagEntity = em.merge(contratoPagamentoEntity);
			if(contratoPagEntity.getIdContratoPagamentoWeb() != 0){
				updated = 1;
			}
			
		} catch (Exception e) {
				System.err.println(e.getMessage());
		}
		return updated;
	}
	
	public int deleteContratoPagamento(List<Integer> pagamentoContratoL){
		System.out.println("[IAM-EJB][deleteContratoPagamento] :");
		int removed = -1;
		try{
			removed = em.createQuery("DELETE ContratoPagamentoWeb cp WHERE cp.idContratoPagamentoWeb IN (:id)")
					.setParameter("id",pagamentoContratoL)
					.executeUpdate();
		} catch (Exception e) {
				System.err.println(e.getMessage());
		}
		return removed;
	}	
}
